/*
 * _coder_master_function_v4_api.c
 *
 * Code generation for function '_coder_master_function_v4_api'
 *
 */

/* Include files */
#include "rt_nonfinite.h"
#include "master_function_v4.h"
#include "_coder_master_function_v4_api.h"

/* Function Declarations */
static real_T b_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId);
static void c_emlrt_marshallIn(const emlrtStack *sp, const mxArray *y, const
  char_T *identifier, real_T **y_data, int32_T y_size[1]);
static void d_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId, real_T **y_data, int32_T y_size[1]);
static void e_emlrt_marshallIn(const emlrtStack *sp, const mxArray *x, const
  char_T *identifier, real_T **y_data, int32_T y_size[2]);
static real_T emlrt_marshallIn(const emlrtStack *sp, const mxArray *t, const
  char_T *identifier);
static const mxArray *emlrt_marshallOut(const real_T u_data[], const int32_T
  u_size[1]);
static void f_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId, real_T **y_data, int32_T y_size[2]);
static void g_emlrt_marshallIn(const emlrtStack *sp, const mxArray
  *transitions_matrix, const char_T *identifier, real_T **y_data, int32_T
  y_size[2]);
static void h_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId, real_T **y_data, int32_T y_size[2]);
static real_T i_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  emlrtMsgIdentifier *msgId);
static void j_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  emlrtMsgIdentifier *msgId, real_T **ret_data, int32_T ret_size[1]);
static void k_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  emlrtMsgIdentifier *msgId, real_T **ret_data, int32_T ret_size[2]);
static void l_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  emlrtMsgIdentifier *msgId, real_T **ret_data, int32_T ret_size[2]);

/* Function Definitions */
static real_T b_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId)
{
  real_T y;
  y = i_emlrt_marshallIn(sp, emlrtAlias(u), parentId);
  emlrtDestroyArray(&u);
  return y;
}

static void c_emlrt_marshallIn(const emlrtStack *sp, const mxArray *y, const
  char_T *identifier, real_T **y_data, int32_T y_size[1])
{
  emlrtMsgIdentifier thisId;
  thisId.fIdentifier = identifier;
  thisId.fParent = NULL;
  d_emlrt_marshallIn(sp, emlrtAlias(y), &thisId, y_data, y_size);
  emlrtDestroyArray(&y);
}

static void d_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId, real_T **y_data, int32_T y_size[1])
{
  j_emlrt_marshallIn(sp, emlrtAlias(u), parentId, y_data, y_size);
  emlrtDestroyArray(&u);
}

static void e_emlrt_marshallIn(const emlrtStack *sp, const mxArray *x, const
  char_T *identifier, real_T **y_data, int32_T y_size[2])
{
  emlrtMsgIdentifier thisId;
  thisId.fIdentifier = identifier;
  thisId.fParent = NULL;
  f_emlrt_marshallIn(sp, emlrtAlias(x), &thisId, y_data, y_size);
  emlrtDestroyArray(&x);
}

static real_T emlrt_marshallIn(const emlrtStack *sp, const mxArray *t, const
  char_T *identifier)
{
  real_T y;
  emlrtMsgIdentifier thisId;
  thisId.fIdentifier = identifier;
  thisId.fParent = NULL;
  y = b_emlrt_marshallIn(sp, emlrtAlias(t), &thisId);
  emlrtDestroyArray(&t);
  return y;
}

static const mxArray *emlrt_marshallOut(const real_T u_data[], const int32_T
  u_size[1])
{
  const mxArray *y;
  static const int32_T iv6[1] = { 0 };

  const mxArray *m2;
  y = NULL;
  m2 = emlrtCreateNumericArray(1, iv6, mxDOUBLE_CLASS, mxREAL);
  mxSetData((mxArray *)m2, (void *)u_data);
  emlrtSetDimensions((mxArray *)m2, u_size, 1);
  emlrtAssign(&y, m2);
  return y;
}

static void f_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId, real_T **y_data, int32_T y_size[2])
{
  k_emlrt_marshallIn(sp, emlrtAlias(u), parentId, y_data, y_size);
  emlrtDestroyArray(&u);
}

static void g_emlrt_marshallIn(const emlrtStack *sp, const mxArray
  *transitions_matrix, const char_T *identifier, real_T **y_data, int32_T
  y_size[2])
{
  emlrtMsgIdentifier thisId;
  thisId.fIdentifier = identifier;
  thisId.fParent = NULL;
  h_emlrt_marshallIn(sp, emlrtAlias(transitions_matrix), &thisId, y_data, y_size);
  emlrtDestroyArray(&transitions_matrix);
}

static void h_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId, real_T **y_data, int32_T y_size[2])
{
  l_emlrt_marshallIn(sp, emlrtAlias(u), parentId, y_data, y_size);
  emlrtDestroyArray(&u);
}

static real_T i_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  emlrtMsgIdentifier *msgId)
{
  real_T ret;
  emlrtCheckBuiltInR2012b(sp, msgId, src, "double", false, 0U, 0);
  ret = *(real_T *)mxGetData(src);
  emlrtDestroyArray(&src);
  return ret;
}

static void j_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  emlrtMsgIdentifier *msgId, real_T **ret_data, int32_T ret_size[1])
{
  int32_T iv7[1];
  boolean_T bv0[1];
  int32_T iv8[1];
  iv7[0] = 10;
  bv0[0] = true;
  emlrtCheckVsBuiltInR2012b(sp, msgId, src, "double", false, 1U, iv7, bv0, iv8);
  ret_size[0] = iv8[0];
  *ret_data = (real_T *)mxGetData(src);
  emlrtDestroyArray(&src);
}

static void k_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  emlrtMsgIdentifier *msgId, real_T **ret_data, int32_T ret_size[2])
{
  int32_T iv9[2];
  boolean_T bv1[2];
  int32_T i0;
  static const boolean_T bv2[2] = { false, true };

  int32_T iv10[2];
  for (i0 = 0; i0 < 2; i0++) {
    iv9[i0] = 1 + 49 * i0;
    bv1[i0] = bv2[i0];
  }

  emlrtCheckVsBuiltInR2012b(sp, msgId, src, "double", false, 2U, iv9, bv1, iv10);
  ret_size[0] = iv10[0];
  ret_size[1] = iv10[1];
  *ret_data = (real_T *)mxGetData(src);
  emlrtDestroyArray(&src);
}

static void l_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  emlrtMsgIdentifier *msgId, real_T **ret_data, int32_T ret_size[2])
{
  int32_T iv11[2];
  boolean_T bv3[2];
  int32_T i;
  int32_T iv12[2];
  for (i = 0; i < 2; i++) {
    iv11[i] = 10;
    bv3[i] = true;
  }

  emlrtCheckVsBuiltInR2012b(sp, msgId, src, "double", false, 2U, iv11, bv3, iv12);
  ret_size[0] = iv12[0];
  ret_size[1] = iv12[1];
  *ret_data = (real_T *)mxGetData(src);
  emlrtDestroyArray(&src);
}

void master_function_v4_api(const mxArray * const prhs[7], const mxArray *plhs[1])
{
  real_T (*dy_data)[10];
  real_T t;
  int32_T y_size[1];
  real_T (*y_data)[10];
  int32_T x_size[2];
  real_T (*x_data)[50];
  int32_T transitions_matrix_size[2];
  real_T (*transitions_matrix_data)[100];
  real_T force_rate;
  int32_T variables_indexes_size[2];
  real_T (*variables_indexes_data)[50];
  int32_T initial_rates_size[2];
  real_T (*initial_rates_data)[50];
  int32_T dy_size[1];
  emlrtStack st = { NULL, NULL, NULL };

  st.tls = emlrtRootTLSGlobal;
  dy_data = (real_T (*)[10])mxMalloc(sizeof(real_T [10]));

  /* Marshall function inputs */
  t = emlrt_marshallIn(&st, emlrtAliasP(prhs[0]), "t");
  c_emlrt_marshallIn(&st, emlrtAlias(prhs[1]), "y", (real_T **)&y_data, y_size);
  e_emlrt_marshallIn(&st, emlrtAlias(prhs[2]), "x", (real_T **)&x_data, x_size);
  g_emlrt_marshallIn(&st, emlrtAlias(prhs[3]), "transitions_matrix", (real_T **)
                     &transitions_matrix_data, transitions_matrix_size);
  force_rate = emlrt_marshallIn(&st, emlrtAliasP(prhs[4]), "force_rate");
  e_emlrt_marshallIn(&st, emlrtAlias(prhs[5]), "variables_indexes", (real_T **)
                     &variables_indexes_data, variables_indexes_size);
  e_emlrt_marshallIn(&st, emlrtAlias(prhs[6]), "initial_rates", (real_T **)
                     &initial_rates_data, initial_rates_size);

  /* Invoke the target function */
  master_function_v4(&st, t, *y_data, y_size, *x_data, x_size,
                     *transitions_matrix_data, transitions_matrix_size,
                     force_rate, *variables_indexes_data, variables_indexes_size,
                     *initial_rates_data, initial_rates_size, *dy_data, dy_size);

  /* Marshall function outputs */
  plhs[0] = emlrt_marshallOut(*dy_data, dy_size);
}

/* End of code generation (_coder_master_function_v4_api.c) */
